﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace lzay5
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr = new int[6];
            for (int i = 0; i < arr.Length; i++)
            {
                while (true)
                {
                    try
                    {
                        Console.WriteLine($"请存入第{i + 1}个数据，数据类型为int");
                        arr[i] = Convert.ToInt32(Console.ReadLine());
                        break;
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("请重新输入");
                    }
                }
            }
            int max1 = arr[0];
            int min1 = arr[0];
            double avg1 = 0;
            int sum1 = GetSum1(arr, ref max1, ref min1, ref avg1);
            Console.WriteLine($"ref ---- sum:{sum1},min:{min1},max:{max1},avg:{avg1}");
            int max2;
            int min2;
            double avg2;
            int sum2 = GetSum2(arr, out max2, out min2, out avg2);
            Console.WriteLine($"out --- sum:{sum2},min:{min2},max:{max2},avg:{avg2}");
        }

        static int GetSum2(int[] arr, out int max, out int min, out double avg)
        {
            int sum = 0;
            max = arr[0];
            min = arr[0];
            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[i] > max)
                {
                    max = arr[i];
                }
                if (arr[i] < min)
                {
                    min = arr[i];
                }
                sum += arr[i];
            }
            avg = (double)sum / arr.Length;
            return sum;
        }
        static int GetSum1(int[] arr, ref int max, ref int min, ref double avg)
        {
            int sum = 0;
            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[i] > max)
                {
                    max = arr[i];
                }
                if (arr[i] < min)
                {
                    min = arr[i];
                }
                sum += arr[i];
            }
            avg = (double)sum / arr.Length;
            return sum;
        }
    }
}
